1 module targets.uwp; 2 version(Windows): 3 import commons; 4 import common_windows; 5 6 private bool installUWPBuildTools(ref Terminal t, ref RealTimeConsoleInput input, out string devConsoleDir) 7 { 8 import features.vs_buildtools_installer; 9 import std.conv:to; 10 11 wchar[] ver, installDir; 12 bool shouldInstall; 13 14 shouldInstall = !detectVSInstallDirViaCOM(ver, installDir); 15 if(!shouldInstall) 16 { 17 import std.file; 18 string install = installDir.to!string; 19 devConsoleDir = buildNormalizedPath(install, "Common7", "Tools", "VsDevCmd.bat"); 20 21 string uwpCheck = buildNormalizedPath(install, "VC", "Tools", "MSVC"); 22 if(!shouldInstall) 23 shouldInstall = !std.file.exists(uwpCheck); 24 if(!shouldInstall) 25 shouldInstall = !std.file.exists(buildNormalizedPath(dirEntries(uwpCheck, SpanMode.shallow).front, "lib", "x64", "uwp")); 26 } 27 28 29 if(shouldInstall) 30 { 31 return installFromVSBuildTools.execute(t, input, "Installing UWP SDK", 32 [ 33 "Microsoft.VisualStudio.Workload.UniversalBuildTools", 34 "Microsoft.VisualStudio.ComponentGroup.UWP.VC.BuildTools", 35 ]); 36 } 37 return true; 38 /** 39 HipremeEngine 40 41 Updates: 42 43 Microsoft.Windows.CppWinRT.2.0.210309.3 -> Microsoft.Windows.CppWinRT.2.0.240405.15 44 45 Needs to install nuget 46 */ 47 } 48 49 50 51 private string getCppWinRt(string basePath) 52 { 53 import std.string; 54 import std.file; 55 if(!std.file.exists(basePath)) 56 return null; 57 foreach(DirEntry e; dirEntries(basePath, SpanMode.shallow)) 58 { 59 if(baseName(e.name).startsWith("Microsoft.Windows.CppWinRT")) 60 return e.name; 61 } 62 return null; 63 } 64 65 ChoiceResult prepareUWP(Choice* c, ref Terminal t, ref RealTimeConsoleInput input, in CompilationOptions cOpts) 66 { 67 import common_windows; 68 import tools.insert_resources_uwp; 69 string vsDevCmd; 70 if(!installUWPBuildTools(t, input, vsDevCmd)) 71 return ChoiceResult.Error; 72 ProjectDetails project; 73 with(WorkingDir(configs["gamePath"].str)) 74 { 75 if(waitRedub(t, DubArguments().command("build").configuration("uwp").compiler("ldc2").opts(cOpts), project) != 0) 76 { 77 t.writelnError("Could not build for UWP. "); 78 return ChoiceResult.Error; 79 } 80 } 81 82 string file = project.getOutputFile(); 83 if(std.file.exists(file)) 84 { 85 t.writelnHighlighted("Renaming ", file, " to hipreme_engine.dll for compatibility. "); 86 string outDirectory = getHipPath("bin", "uwp"); 87 if(!std.file.exists(outDirectory)) 88 std.file.mkdirRecurse(outDirectory); 89 std.file.rename(file, getHipPath("bin", "uwp", "hipreme_engine.dll")); 90 } 91 92 if(!insertUWPResources(t, getHipPath("build", "uwp", "HipremeEngine", "HipremeEngine"), buildNormalizedPath(configs["gamePath"].str, "assets"))) 93 { 94 t.writelnError("Could not insert UWP resources."); 95 return ChoiceResult.Error; 96 } 97 98 with(WorkingDir(getHipPath("build", "uwp", "HipremeEngine"))) 99 { 100 string nugetPath = getHipPath("build", "uwp", "HipremeEngine", "packages"); 101 if(!getCppWinRt(nugetPath)) 102 { 103 import features.nuget; 104 if(!installWithNuGet.execute(t, input, "being able to build with MSBuild.", "Microsoft.Windows.CppWinRT -Version 2.0.240405.15", nugetPath)) 105 { 106 t.writelnError("Download Failure: This package is needed for executing build on UWP"); 107 return ChoiceResult.Error; 108 } 109 } 110 111 t.wait(spawnShell( 112 "\""~vsDevCmd~ "\"" ~" && " ~ 113 "msbuild HipremeEngine.sln /m /p:Configuration=Debug /p:Platform=x64" 114 )); 115 } 116 117 118 return ChoiceResult.Continue; 119 }